package require TclOO
namespace import oo::*

class create Module {
   constructor {} {
    my variable modulename
    my variable dir 
    my variable loaded
    set modulename [self name]
    set dir [file directory [info script]]
    namespace eval $modulename {} 
   }
}

define Module method load { fname } {
   # search for file 
   my variable dir
   my variable loaded
   set search_dirs [list [file join $dir $fname] $fname ]
   foreach f $search_dirs {
     if [file exists $f] { set fname $f; break}
   }
   #do nothing if file already loaded
   if { [lsearch $loaded $fname] >=0} { return}
   lappend loaded $fname
   set modulefile [ open $fname r]
   set body [read $modulefile]
   close $modulefile
   namespace eval $modulename $body
}

proc module { load fname } {}

proc source2 { fname} {
   global loaded
   if ![info exists loaded] { set loaded {}}
   set mydir [file dirname [dict get [info frame [info frame]] file ]]
   foreach f [list [file join $mydir $fname] $fname ] {
      if [file exists $f] {set fname $f; break}
   }
   if {[lsearch $loaded $fname] <0} { return}
   lappend loaded $fname
   source $fname
}
